package com.talkyun.utils.para;


import com.thoughtworks.paranamer.CachingParanamer;
import com.thoughtworks.paranamer.Paranamer;

import java.lang.reflect.AccessibleObject;
import java.util.ArrayList;
import java.util.List;

public class MixedParaNamer implements Paranamer {
    private final List<Paranamer> list = new ArrayList<>(2);

    public MixedParaNamer() {
        list.add(new SpringImplParanamer());
        list.add(new CachingParanamer());
    }

    @Override
    public String[] lookupParameterNames(AccessibleObject ao) {
        for (Paranamer paranamer : list) {
            String[] names = paranamer.lookupParameterNames(ao);
            if (names != null && names.length > 0) {
                return names;
            }
        }
        return EMPTY_NAMES;
    }

    @Override
    public String[] lookupParameterNames(AccessibleObject ao, boolean throwsIfMiss) {
        return lookupParameterNames(ao);
    }

}
